//
//  ViewController.m
//  inner
//
//  Created by Pro on 2022/1/12.
//

#import "ViewController.h"

@interface ViewController ()
//@property(nonatomic,strong)UIView * redView;
//@property(nonatomic,strong)UIView * grayView;
//@property(nonatomic,strong)UIView * blueView;
//@property(nonatomic,strong)UIView * cycaView;
@property(nonatomic,strong)CALayer * redLayer;
@property(nonatomic,strong)CALayer * grayLayer;
@property(nonatomic,strong)CALayer * blueLayer;
@property(nonatomic,strong)CALayer * cycaLayer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.redLayer = [[CALayer alloc] init];
    self.redLayer.backgroundColor = [UIColor redColor].CGColor;
    self.redLayer.frame = CGRectMake(100, 100, 200, 200);
    [self.view.layer addSublayer:self.redLayer];
    
    
//    self.redView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
//    self.redView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:self.redView];
//
    self.grayLayer = [[CALayer alloc] init];
    self.grayLayer.backgroundColor = [UIColor grayColor].CGColor;
    self.grayLayer.frame = CGRectMake(0, 0, 80, 80);
    [self.redLayer addSublayer:self.grayLayer];
    
//    self.grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
//    self.grayView.backgroundColor = [UIColor grayColor];
//    [self.redView addSubview:self.grayView];
    
    self.blueLayer = [[CALayer alloc] init];
    self.blueLayer.backgroundColor = [UIColor blueColor].CGColor;
    self.blueLayer.frame = CGRectMake(100, 300, 200, 200);
    [self.view.layer addSublayer:self.blueLayer];
    
    self.cycaLayer = [[CALayer alloc] init];
    self.cycaLayer.frame = CGRectMake(0, 0, 90, 90);
    self.cycaLayer.backgroundColor = [UIColor cyanColor].CGColor;
    [self.blueLayer addSublayer:self.cycaLayer];
//
//    self.blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 200, 200)];
//    self.blueView.backgroundColor = [UIColor blueColor];
//    [self.view addSubview:self.blueView];
//
//    self.cycaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
//    self.cycaView.backgroundColor = [UIColor cyanColor];
//    [self.blueView addSubview:self.cycaView];
//
//    CGPoint point = [self.redView convertPoint:CGPointMake(10, 10) toView:self.blueView];
//    NSLog(@"redview上10，10的这个点，在blueview上的实际坐标是：%@",NSStringFromCGPoint(point));
    CGPoint  point = [self.redLayer convertPoint:CGPointMake(10, 10) toLayer:self.blueLayer];
    NSLog(@"red layer 上的10 10 这个点 在bluelayer 上的坐标为 %@",NSStringFromCGPoint(point));
//
//    CGPoint point2 = [self.redView convertPoint:CGPointMake(10, 10) fromView:self.blueView];
//    NSLog(@"blueview上 10 10 的这个点，在redview上的实际坐标是：%@",NSStringFromCGPoint(point2));
    
    CGPoint point2 = [self.redLayer convertPoint:CGPointMake(10, 10) fromLayer:self.blueLayer];
    NSLog(@"self.bluelayer上的10 10 这个点在self.redLayer上的坐标是%@",NSStringFromCGPoint(point2));
//
//    CGRect rect = [self.redView convertRect:self.grayView.frame toView:self.blueView];
//    NSLog(@"redview上的子视图的grayview的frame 在blueview上的实际frame是%@",NSStringFromCGRect(rect));
    CGRect rect = [self.redLayer convertRect:self.grayLayer.frame toLayer:self.blueLayer];
    NSLog(@"redlayer 上的一个rect 在blueLayer上的位置 %@",NSStringFromCGRect(rect));
//
//    CGRect rect2 = [self.redView convertRect:self.cycaView.frame fromView:self.blueView];
//    NSLog(@"blueview上的子视图的cycanview的frame 在redview上的实际frame是%@",NSStringFromCGRect(rect2));
    CGRect rect2 = [self.redLayer convertRect:self.cycaLayer.frame fromLayer:self.blueLayer];
    NSLog(@"bluylayer 上的rect相对于 redlayer的位置 %@",NSStringFromCGRect(rect2));
//    判断一个点是否在一个视图上
//    BOOL isInside = [self.blueView pointInside:redCenterInBlueView withEvent:nil];
    
    
    
}



@end



